import {
  getTechnologyListByCrossShop as getMesTechnologyList,
  getTechnologyTypeList as getMesTechnologyTechnologyTypeList,
  getTechnologyStatusList as getMesTechnologyTechnologyStatusList
} from '@/api/order/mesTechnology'
import { getStationCodeList } from '@/api/order/mesProdOrder'
import { getYesOrNotList } from "@/api/process/mesProcess"
export const mesTechnologyDialog = {
  data () {
    return {
      mesTechnologyDialogVisible: false, //表格弹框隐藏显示
      getMesTechnologyList, // 获取弹框数据接口
      hasMesTechnologyFooter: true, // 是否需要底部按钮默认true
      mesTechnologySearchDialog: {
        inline: true,
        formDesc: {
        }
      },
      mesTechnologyDialogColumn: [
        {
          type: 'selection'
        },
        {
          type: 'index',
          label: $i18n.t('common.order'),
          fixed: 'left',
          width: 60
        },
        {
          prop: 'technologyCode',
          label: $i18n.t('mesProdOrderPlan.technologyCode'),
          showOverflowTooltip: true,
          minWidth: 140
        },
        {
          prop: 'technologyName',
          label: $i18n.t('mesProdOrderPlan.technologyName'),
          showOverflowTooltip: true,
          minWidth: 140
        },
        {
          prop: "isDefaultTechnology",
          label: $i18n.t("mesProdOrderPlan.isDefaultTechnology"),
          minWidth: 160,
          showOverflowTooltip: true,
          require: true,
          optionProp: {
            value: "value",
            label: "description"
          },
          option: async (data) => {
            const list = await getYesOrNotList()
            return list.data.result
          }
        },
        {
          prop: "processNum",
          label: $i18n.t("mesProdOrderPlan.processNum"),
          minWidth: 80,
          showOverflowTooltip: true
        },
        {
          prop: 'technologyType',
          label: $i18n.t('mesProdOrderPlan.technologyType'),
          showOverflowTooltip: true,
          optionProp: {
            value: 'value',
            label: 'description'
          },
          option: async (data) => {
            const list = await getMesTechnologyTechnologyTypeList()
            return list.data.result
          },
          minWidth: 130
        },
        {
          prop: 'prodCodeStr',
          label: $i18n.t('mesProdOrderPlan.prodCode'),
          minWidth: 160,
          showOverflowTooltip: true
        },
        {
          prop: 'prodNameStr',
          label: $i18n.t('mesProdOrderPlan.prodName'),
          minWidth: 160,
          showOverflowTooltip: true
        },
        {
          prop: 'versionNumber',
          label: $i18n.t('mesProdOrderPlan.versionNumber'),
          showOverflowTooltip: true,
          width: 140
        },
        {
          prop: "technologyStatus",
          label: $i18n.t("mesProdOrderPlan.technologyStatus"),
          showOverflowTooltip: true,
          optionProp: {
            value: "value",
            label: "description"
          },
          option: async (data) => {
            const list = await getMesTechnologyTechnologyStatusList()
            return list.data.result
          }
        },
        {
          prop: 'Remark',
          label: $i18n.t('common.remark'),
          showOverflowTooltip: true,
          minWidth: 130
        },
        {
          prop: 'createByName',
          label: $i18n.t('common.createByName'),
          width: 160,
          showOverflowTooltip: true
        },
        {
          prop: 'createTime',
          label: $i18n.t('common.createTime'),
          width: 180
        },
        {
          prop: 'updateByName',
          label: $i18n.t('common.updateByName'),
          width: 160,
          showOverflowTooltip: true
        },
        {
          prop: 'updateTime',
          label: $i18n.t('common.updateTime'),
          width: 180
        }
      ]
    }
  },
  methods: {
    transFormdatas (data) {
      return Promise.resolve({
        records: data.data.result,
        total: 0
      })
    },

    // 弹框表格，双击表格，或者点击确定 返回选中数据
    async getSelectMesTechnology (data) {
      // 调试完成记得删除控制台打印
      console.log('选中数据', data)
      // 这里可以自定义返回字段信息
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      this.$set(this.pcDescDialog.orderList[this.techIndex], 'technologyId', data[0].id)
      this.$set(this.pcDescDialog.orderList[this.techIndex], 'technologyCode', data[0].technologyCode)
      this.$set(this.pcDescDialog.orderList[this.techIndex], 'technologyName', data[0].technologyName)
      this.$set(this.pcDescDialog.orderList[this.techIndex], 'versionNumber', data[0].versionNumber)
      // 获取工位数据
      if (this.pcDescDialog.orderList[this.techIndex].lineCode) {
        const params = {
          lineCode: this.pcDescDialog.orderList[this.techIndex].lineCode,
          technologyId: data[0].id
        }
        const list = await getStationCodeList(params)
        this.pcDescDialog.orderList[this.techIndex].stationList = list.data.result
      }
    }
  }
}
